// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data;
using System.Text;
using JetBrains.Annotations;

namespace SnapObjects.Data.PostgreSql
{
    public class PostgreSqlObjectTypeMapping : TypeMapping
    {
        public PostgreSqlObjectTypeMapping([NotNull] string dbTypeName,
            [NotNull] Type clrType,
            [CanBeNull] DbType? dbType = null,
            bool unicode = false, int? size = null) : base(dbTypeName, clrType, dbType, unicode, size)
        {
        }

        public TypeMapping ElementMapping { get; }

        public override TypeMapping Clone([NotNull] string dbTypeName, int? size)
        {
            throw new NotImplementedException();
        }

        protected override bool IsAssignable(Type modelType, Type dbType)
        {
            return dbType.IsAssignableFrom(modelType);
        }

        public override object ChangeDbType(object dbValue)
        {
            if (Convert.IsDBNull(dbValue))
            {
                return null;
            }

            return dbValue;
        }
    }
}
